package com.freewater.springboot.demo.aop.apectj.injectdomain;

import com.freewater.springboot.demo.aop.apectj.injectdomain.context.AuthContext;
import com.freewater.springboot.demo.aop.apectj.injectdomain.repository.AccountRepository;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.aspectj.EnableSpringConfigured;

import java.util.UUID;

@Configuration
@EnableSpringConfigured // 使类AnnotationBeanConfigurerAspect被注册
@EnableLoadTimeWeaving // 开启加载类到jvm时的AspectJ Weaving
public class AppConfig {

    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @Bean
    public AuthContext authContext() {
        return new AuthContext(UUID.randomUUID().toString().replaceAll("-", ""));
    }

    @Bean
    public AccountRepository accountRepository() {
        return new AccountRepository();
    }

}
